<?php

namespace App\Library\Rules;

use Illuminate\Contracts\Validation\Rule;

class ExpressesNoRule implements Rule
{
    private string $errorMessage = '快递号错误';

    /**
     * Desc:
     * @param string $attribute
     * @param mixed $value
     * @return boolean
     */
    public function passes($attribute, $value): bool
    {
        $this->errorMessage = $attribute . ' ' . $this->errorMessage;

        $expressArr = array_filter(explode(',', $value), function ($v) {
            return $v !== '';
        });
        foreach($expressArr as $v) {
            if (!preg_match(__('com.expressNoReg'), $v)) return false;
        }
        return true;
    }

    /**
     * Desc:
     * @return string
     */
    public function message(): string
    {
        return $this->errorMessage;
    }
}
